<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Database.pb</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font><font color="#006666">;   PureBasic - Database example file
</font><font color="#006666">;
</font><font color="#006666">;    (c) Fantaisie Software
</font><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font>
<font color="#006666">UseSQLiteDatabase</font>()

<b><font color="#006666">Procedure</font></b> <font color="#006666">CheckDatabaseUpdate</font>(Database, Query$)
   Result =<font color="#006666"> DatabaseUpdate</font>(Database, Query$)
   <b><font color="#006666">If</font></b> Result = 0
      <b><font color="#006666">Debug</font></b> <font color="#006666">DatabaseError</font>()
   <b><font color="#006666">EndIf</font></b>
   
   <b><font color="#006666">ProcedureReturn</font></b> Result
<b><font color="#006666">EndProcedure</font></b>

DatabaseFile$ =<font color="#006666"> GetTemporaryDirectory</font>()+"Database.sqlite"

<b><font color="#006666">If</font></b> <font color="#006666">CreateFile</font>(0, DatabaseFile$)
<font color="#006666">   CloseFile</font>(0)
   
   <b><font color="#006666">If</font></b> <font color="#006666">OpenDatabase</font>(0, DatabaseFile$, "", "")
   
<font color="#006666">      CheckDatabaseUpdate</font>(0, "CREATE TABLE food (name CHAR(50), weight INT)")

<font color="#006666">      CheckDatabaseUpdate</font>(0, "INSERT INTO food (name, weight) VALUES ('apple', '10')")
<font color="#006666">      CheckDatabaseUpdate</font>(0, "INSERT INTO food (name, weight) VALUES ('pear', '5')")
<font color="#006666">      CheckDatabaseUpdate</font>(0, "INSERT INTO food (name, weight) VALUES ('banana', '20')")
      
      <b><font color="#006666">If</font></b> <font color="#006666">DatabaseQuery</font>(0, "SELECT * FROM food WHERE weight &gt; 7")
      
         <b><font color="#006666">While</font></b> <font color="#006666">NextDatabaseRow</font>(0)
            <b><font color="#006666">Debug</font></b> <font color="#006666">GetDatabaseString</font>(0, 0)
         <b><font color="#006666">Wend</font></b>
      
<font color="#006666">         FinishDatabaseQuery</font>(0)
      <b><font color="#006666">EndIf</font></b>
      
<font color="#006666">      CloseDatabase</font>(0)
   <b><font color="#006666">Else</font></b>
      <b><font color="#006666">Debug</font></b> "Can't open database !"
   <b><font color="#006666">EndIf</font></b>
<b><font color="#006666">Else</font></b>
   <b><font color="#006666">Debug</font></b> "Can't create the database file !"
<b><font color="#006666">EndIf</font></b>
</font></pre>
</body></html>
